package com.suyuan.service.impl;

import com.suyuan.dao.StationMapper;
import com.suyuan.dao.TransportrouteInforMapper;
import com.suyuan.entity.Station;
import com.suyuan.entity.StationExample;
import com.suyuan.entity.TransportRouteInfor;
import com.suyuan.entity.TransportRouteInforExample;
import com.suyuan.service.StationService;
import com.suyuan.vo.StationVO;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by yang on 2018/5/19.
 */
@Service(value = "stationService")
@Transactional
public class StationServiceImpl implements StationService{
    @Resource
    private StationMapper stationMapper;
    @Resource
    private TransportrouteInforMapper routeMapper;

    public List<StationVO> list() {
        List<Station> stations = stationMapper.selectByExample(new StationExample());

        List<StationVO> vos = new ArrayList<StationVO>();
        for(Station station : stations){
            TransportRouteInfor route = routeMapper.selectByPrimaryKey(station.getRouteid());
            vos.add(new StationVO(station,route));
        }
        return vos;
    }

    public int add(Station station) {
        return stationMapper.insertSelective(station);
    }

    public int delete(Integer id) {
        return stationMapper.deleteByPrimaryKey(id);
    }

    public Station edit(Integer id) {
        return stationMapper.selectByPrimaryKey(id);
    }

    public int update(Station station) {
        return stationMapper.updateByPrimaryKey(station);
    }

    public List<TransportRouteInfor> getRoutes() {
        return routeMapper.selectByExample(new TransportRouteInforExample());
    }
}
